//
//  SetSexView.m
//  Toyohu
//
//  Created by GuoPeng on 16/5/5.
//  Copyright © 2016年 celia. All rights reserved.
//

#import "SetSexView.h"
#import "FlatButton.h"

typedef void(^SuccessBlock)(BOOL sex);

typedef enum : NSUInteger {
    Boy = 1,
    Girl = 0
} Sex;

@interface SetSexView ()



@property (weak, nonatomic) IBOutlet FlatButton *determineButton;

@property (weak, nonatomic) IBOutlet FlatButton *boyButton;
@property (weak, nonatomic) IBOutlet FlatButton *girlButton;
@property (weak, nonatomic) IBOutlet UIImageView *boyImage;
@property (weak, nonatomic) IBOutlet UIImageView *girlImage;

@property (nonatomic, copy) SuccessBlock success;
@property (nonatomic, assign) Sex sex;

@end

@implementation SetSexView

- (IBAction)determineClick:(id)sender
{
    self.success(_sex);
    [self removeFromSuperview];
}
- (IBAction)boyClick:(id)sender
{
    [self isBoy];
}

- (IBAction)girlClick:(id)sender
{
    [self isGirl];
}

- (void)isGirl
{
    self.sex = Girl;
    self.boyImage.hidden = YES;
    self.girlImage.hidden = NO;
}

- (void)isBoy
{
    self.sex = Boy;
    self.boyImage.hidden = NO;
    self.girlImage.hidden = YES;
}

+ (void)showWithSex:(BOOL)sex success:(void(^)(BOOL sex))block;
{
    [[[self alloc] init] initWithSuccessBlock:^(BOOL sex) {
        
//        [TieSuccessV show];
        block(sex);
        
    } frame:[[UIScreen mainScreen] bounds] sex:sex];
}

- (instancetype)initWithSuccessBlock:(void(^)(BOOL sex))successBlock frame:(CGRect)frame sex:(BOOL)sex
{
    self = [[[NSBundle mainBundle] loadNibNamed:@"SetSexView" owner:self options:nil] objectAtIndex:0];
    if (self) {
        self.frame = frame;
        
        if (sex) {
            [self isBoy];
        } else {
            [self isGirl];
        }
        
//        [self initView];
//        [self bindEvents];
        self.success = successBlock;
//        self.oldValidCodeStr = vCode;
        [[[UIApplication sharedApplication] keyWindow] addSubview:self];
        
    }
    return self;
    
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
